package pattern24;

import java.util.ArrayList;
import java.util.List;

/**
 * 枚举元素，提供一个高层的接口以运行访问者访问它的元素
 *
 * @author wdl
 */
public class ObjectStructure {
    private List<IElement> elements = new ArrayList<>();

    public void attach(IElement element) {
        elements.add(element);
    }

    public void detach(IElement element) {
        elements.remove(element);
    }

    public void accept(IVisitor visitor) {
        for (IElement e : elements) {
            e.accept(visitor);
        }
    }
}
